

const getFarmList = async ctx => {

  let farmList = await ctx.db.execute('select * from farm');
  console.log(farmList);

  let res = farmList.map(async item => {
    return await ctx.db.execute(`select am.amId,am.amName from farm_am 
    LEFT Join farm On
    farm.farmId = farm_am.faId
    LEFT Join am On farm_am.amId = am.amId where farm.farmId = ${item.farmId}`);
  });

  let result = await Promise.all(res);
  farmList.forEach((item, index) => {
    result[index].length!==0? item.am = result[index]:item.am = [];
  });
  ctx.body = {
    code: 1,
    data: farmList
  };
};

module.exports = {
  getFarmList
};